#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    string changeStr(string s)
    {
        string ret;
        for (char ch : s)
        {
            if (ch == '#')
            {
                if (ret.size())
                    ret.pop_back();
            }
            else
            {
                ret.push_back(ch);
            }
        }
        return ret;
    }

    bool backspaceCompare(string s, string t) {
        return changeStr(s) == changeStr(t);
    }
};